<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

  <style>
    .outer {
      height: 200px;
      background-color: red;
      padding: 10px;
    }

    .inner {
      height: 100px;
      background-color: blue;
      margin-top: 50px;
    }
  </style>
</head>
<body>
  <div class="outer">
    <div class="inner"></div>
  </div>
</body>

<script>
let inner = document.querySelector('.inner')
let outer = document.querySelector('.outer')

// 监听outer元素的attribute变化
new MutationObserver(function() {
  console.log('mutate')
}).observe(outer, {
  attributes: true
})

// click监听事件
function onClick() {
    console.log('click')
    setTimeout(function() {
        console.log('timeout')
    }, 0)
 
    Promise.resolve().then(function() {
        console.log('promise')
    })
    outer.setAttribute('data-random', Math.random())
}

inner.addEventListener('click', onClick)
outer.addEventListener('click', onClick)
</script>
</html>
